package cron

import (
	"fmt"
	"github.com/robfig/cron/v3"
	"tourism-app/common/models/mysql"
)

func GetOrderStatus(orderId string) {
	c := cron.New(cron.WithSeconds())
	c.AddFunc("* */30 * * * ?", func() {
		o := &mysql.Order{}
		status, err := o.GetStatus(orderId)
		if err != nil {
			return
		}
		if status.Status == 0 {
			err = o.UpdateOrderStatus(orderId, 1)
			if err != nil {
				fmt.Println("修改失败")
				return
			}
		}
		if status.Status == 1 {
			c.Stop()
		}
	})
	c.Start()
}
